#include "rationalhandle.h"
#include "curvelib/irational.h"
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneWheelEvent>

RationalHandle::RationalHandle(RationalCurveItem *curve, int i, qreal radius)
    : Handle(curve, curve->GetControlPointsPtr(), i, radius)
{
    m_numCurve = curve->GetNumCurve();
    setToolTip("uchwyt wymierny");
}

void RationalHandle::wheelEvent(QGraphicsSceneWheelEvent *event)
{
    if (event->delta() > 0)
    {
        RaiseWeight();
    }
    else
    {
        LowerWeight();
    }
}

void RationalHandle::RaiseWeight()
{
    double newW = m_numCurve->GetWeight(m_i) + 1;
        m_numCurve->SetWeight(m_i, newW);
}

void RationalHandle::LowerWeight()
{
    double newW = m_numCurve->GetWeight(m_i) - 1;
    if (0.0 <= newW)
    {
        m_numCurve->SetWeight(m_i, newW);
    }
}

QVariant RationalHandle::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
    Handle::itemChange(change, value);
}
